/*
 * C_CRC16.c
 *
 *  Created on: Sep 17, 2025
 *      Author: ADMIN
 */

#include "C_CRC16.h"

uint16_t CalculateCRC16(uint8_t data[], int length)
{
    uint16_t crc = 0xFFFF; // CRC初始值
    uint16_t polynomial = 0xA001; // CRC多项式

    for (int j = 0; j < length; j++)
    {
        crc ^= data[j];
        for (int i = 0; i < 8; i++)
        {
            if ((crc & 0x0001) != 0)
            {
                crc = (crc >> 1) ^ polynomial;
            }
            else
            {
                crc = crc >> 1;
            }
        }
    }
    return crc;
}

uint8_t compare_arrays(uint8_t* a, uint8_t* b, int size)
{
    for (int i = 0; i < size; i++) {
        if (a[i] != b[i]) {
            return 0; // 发现任何一个不相等的元素，立即返回 false
        }
    }
    return 1; // 所有元素都相等，返回 true
}
